<?php

namespace app\merchant\controller;

use app\common\model\GoodsComment as GoodsCommentModel;

class GoodsComment extends Common
{
	public function showlist()
	{
		$pagesize = (int)input('param.DataTables_Table_0_length', 10);
		$data = GoodsCommentModel::showlist($pagesize);
		// return json($data['not_reply']);\
        $type = input("type/n",0);
		$this->assign([
			'replyed' => $data['replyed'],
			'not_reply' => $data['not_reply'],
            'type' => $type,
		]);
		return view('showlist');
	}

	/**
     * 图书评论
	*/
    public function showbooklist()
    {
        $pagesize = (int)input('param.DataTables_Table_0_length', 10);
        $data = GoodsCommentModel::showbooklist($pagesize);
        // return json($data['not_reply']);
        $type = input("type/n",0);
        $this->assign([
            'replyed' => $data['replyed'],
            'not_reply' => $data['not_reply'],
            'type' => $type,
        ]);
        return view('showbooklist');
    }
	
	public function comment()
	{
		$commentId = (int)input('param.commentId');
		$data = GoodsCommentModel::find($commentId);
		return returnJson(1, 'Request is ok', $data);
	}
	// public function commentData()
	// {
	// 	$pagesize =  (int)input('param.DataTables_Table_0_length');
	// 	$data = GoodsCommentModel::showlist($pagesize);
		
	// 	$data = [
	// 		'replyed' => $data['replyed'],
	// 		'not_reply' => $data['not_reply'],
	// 	];
			
	// 	return returnJson(1, '评论返回成功', $data);

	// }
     public function insert()
	{ 
		$comment_id = input('param.comment_id');
		$content = input('param.content');
		// halt($comment_id);
		$result = GoodsCommentModel::insertGoodsCommentReplay([
			'replay_merchant_id' =>  session('merchant.merchant_id'),
			'comment_id' => $comment_id,
			'replay_reply' => $content,
			'replay_create_time' => time(),
		]);
		if(!$result)
		{
			return returnJson(0, '数据更新失败，请稍后重试');
		}

		return returnJson(1, '回复成功');
	}
	
}